package jmine.tec.security.impl.pack;

import java.util.Collections;

import jmine.tec.database.pack.populator.AbstractPopulatorDataSource;
import jmine.tec.database.pack.populator.PopulatorBean;
import jmine.tec.security.impl.export.AllCredentials;
import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.security.impl.domain.Credential;
import bancosys.tec.security.impl.domain.MetaCredential;

/**
 * Populador de pack do módulo security
 * 
 * @author lundberg
 */
public class SecurityPopulatorDataSource extends AbstractPopulatorDataSource<AllCredentials> {

    private BaseDAO<MetaCredential> metaCredentialDAO;

    private BaseDAO<Credential> credentialDAO;

    /**
     * {@inheritDoc}
     */
    public Iterable<PopulatorBean<AllCredentials>> load() {
        if (this.metaCredentialDAO.countAll() == 0 && this.credentialDAO.countAll() == 0) {
            return Collections.emptyList();
        } else {
            return Collections.singleton(new PopulatorBean<AllCredentials>(new AllCredentials(), "security", "credentials.xml"));
        }
    }

    /**
     * @param metaCredentialDAO the metaCredentialDAO to set
     */
    public void setMetaCredentialDAO(BaseDAO<MetaCredential> metaCredentialDAO) {
        this.metaCredentialDAO = metaCredentialDAO;
    }

    /**
     * @param credentialDAO the credentialDAO to set
     */
    public void setCredentialDAO(BaseDAO<Credential> credentialDAO) {
        this.credentialDAO = credentialDAO;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "SecurityPopulatorDataSource";
    }
}
